package oracle.apps.financials.collection.listener;

import greendroid.widget.item.ProgressItem;
import oracle.apps.financials.collection.activity.TopDelinquentCustomerActivity;
import oracle.apps.financials.collection.po.Customer;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.PopupWindow;

public abstract class BaseOnClickListener implements OnClickListener, OnLongClickListener, OnItemClickListener {

	protected static final String TAG = BaseOnClickListener.class.getSimpleName();

	protected final ProgressItem progressItem = new ProgressItem("Loading...", true);
	protected Context context = null;
	protected Customer customer;
	protected PopupWindow popupWindow;
	protected View popupWindowView;
	protected LayoutInflater mLayoutInflater;
	protected Handler mHandler;

	public BaseOnClickListener(Context context, int layout, Customer customer) {
		this(context, layout, customer, null);
	}

	public BaseOnClickListener(Context context, int layout, Customer customer, Handler mHandler) {
		this.context = context;
		this.customer = customer;
		this.mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.popupWindowView = this.getView(layout);
		this.mHandler = mHandler;
	}

	public BaseOnClickListener(Context context, Customer customer) {
		this(context, 0, customer);
	}

	public View getView(int layout) {
		if (layout == 0) {
			return null;
		}
		return mLayoutInflater.inflate(layout, null);
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

	}

	@Override
	public void onClick(View parent) {

	}

	@Override
	public boolean onLongClick(View v) {
		// TODO Auto-generated method stub
		return false;
	}

	public void refreshData(Object obj) {
		if (obj instanceof Customer) {
			this.customer = (Customer) obj;
		}

	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public void dismissPopupWindow() {
		if (popupWindow != null) {
			popupWindow.dismiss();
			popupWindow = null;

		}
	}

	public void notifyHandler(Customer customer) {
		Message message = new Message();
		message.what = 1;
		message.obj = customer;
		mHandler.sendMessage(message);
	}

}
